var selectValue = '1';
$(function () {
    $("#jqGrid").jqGrid({
        url: '/sys/transRecord/list',
        datatype: "json",
        colModel: [
            { label: 'recordId', name: 'recordId', index: 'recordId', width: 50, key: true ,hidden:true},
            { label: '交易用户', name: 'userId', index: 'userId', width: 80 },
            { label: '交易金额', name: 'money', index: 'money', width: 50 },
            { label: '交易类型', name: 'recordType', index: 'recordType', width: 50, formatter: function(value, options, row){
                    if (value == '1'){
                        return '钱包充值';
                    }else if (value == '-1')
                        return '钱包提现';
                    else if (value == '2')
                        return '返佣充值';
                    else if (value == '-2')
                        return '返佣提现';
                    else if (value == '3')
                        return '积分获取';
                    else if (value == '-3')
                        return '积分兑换';
                    else if (value == '-4')
                        return '提现到卡';
                    else if (value == '4')
                        return '账户充值';
                    else
                        return '未知信息';
            }},
            { label: '交易状态', name: 'recordStatus', index: 'recordStatus', width: 50, formatter: function(value, options, row){
                return value == '0' ?
                    '<span class="label label-success">成功</span>' :
                    '<span class="label label-danger">失败</span>';
            }},
            { label: '交易说明', name: 'remark', index: 'remark', width: 100 },
            { label: '交易时间', name: 'createDate', index: 'createDate', width: 100 }
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "data.list",
            page: "data.currPage",
            total: "data.totalPage",
            records: "data.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        loadComplete:function (data) {
            console.log("data",data);
        },
        gridComplete:function(){
            //隐藏grid底部滚动条\
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    $("#select_type").change(function () {
        var value = $(this).val();
        var urlStr = "";
        if (value == '1'){
            urlStr = "/sys/transRecord/list";
        }else {
            urlStr = "/sys/transRecord/list?appId="+value;
        }
        $("#jqGrid").jqGrid("setGridParam",{
            url:urlStr
        }).trigger("reloadGrid");
        selectValue = value;
    });
    vm.loadApps();
});

var vm = new Vue({
    el:"#rrapp",
    data:{
        showList:true,
        apps:[]
    },
    methods:{
        loadApps:function () {
            $.ajax({
                url:"/sys/app/list?page=1&limit=1000",
                type:"POST",
                dataType:"JSON",
                success:function (result) {
                    if (result.code == 0){
                        vm.apps = result.data.list;
                    }else
                        alert(result.msg);
                },
                error:function (e) {
                    console.log("error",e);
                    alert("请求失败，请重试")
                }
            })
        },
        query:function () {
            var urlStr = "";
            var search = $("#searchContent").val();
            if (selectValue != '1'){
                if (search != null && search.length > 0){
                    urlStr = "/sys/transRecord/list?appId="+selectValue +"&search="+search;
                }else
                    urlStr = "/sys/transRecord/list?appId="+selectValue;
            }else {
                if (search != null && search.length > 0){
                    urlStr = "/sys/transRecord/list?search="+search;
                }else
                    urlStr = "/sys/transRecord/list";
            }
            $("#jqGrid").jqGrid("setGridParam",{
                url:urlStr
            }).trigger("reloadGrid");
        },
        info:function () {
            
        }
    }
});